package com.xu.boot.controller;

import com.xu.boot.bean.Car;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

// @RestController = @Controller + @ResponseBody
@RestController
@Slf4j
public class HelloController {

    @Autowired
    public Car car;

    // 由于要返回一个字符串给浏览器，所以需要加上 @ResponseBody 注解，而如果一个类中的所有方法
    // 都需要返回字符串给浏览器，那么就可以给 HelloController 类加上 @ResponseBody 注解
    @RequestMapping("/hello")
    public String handle01(@RequestParam("name") String name){
        log.info("请求进来了");
        return "Hello, Spring Boot 2! " + name;
    }

    @RequestMapping("/car")
    public Car car(){
        return car;
    }
}
